﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HzybService
{
    public class HzybRc
    {
        /// <summary>
        /// 交易类型
        /// </summary>
        public string JiaoYiLx { set; get; } = "";

        /// <summary>
        /// 交易类型名称
        /// </summary>
        public string JiaoYiLxmc { set; get; } = "";

        /// <summary>
        /// 医院代码
        /// </summary>
        public string YiYuanDm { set; get; } = "";

        /// <summary>
        /// 操作员代码
        /// </summary>
        public string CaoZuoYuanDm { set; get; } = "";

        /// <summary>
        /// 业务周期号
        /// </summary>
        public string YeWuZqh { set; get; } = "";

        /// <summary>
        /// 参保地统筹区
        /// </summary>
        public string CanBaoDtcq { set; get; } = "";

        /// <summary>
        /// 医院交易流水号
        /// </summary>
        public string YiYuanJylsh { set; get; } = "";

        /// <summary>
        /// 持卡类型
        /// </summary>
        public string KaLeiXing { set; get; } = "";

        /// <summary>
        /// 入参
        /// </summary>
        public string RuCan { set; get; } = "";

        /// <summary>
        /// 联机标志
        /// </summary>
        public string LianJiBz { set; get; } = "";

        /// <summary>
        /// 门诊住院流水号(一次就诊的序号，医院系统生成，与HIS系统进行关联)
        /// </summary>
        public string MzzyLsh { set; get; } = "";

        /// <summary>
        /// 校验错误信息
        /// </summary>
        public string _ErrText { get; set; } = "";

        public string BingRenId { set; get; } = "";

        public HzybRc()
        {
            YiYuanDm = "H33010900813";
            CaoZuoYuanDm = "000HIS";
            LianJiBz = "1";
            YiYuanJylsh = HzybConstants.GetYiYuanJylsh();
            //获取业务周期号
            YeWuZqh = HzybConstants.GetYeWuZqh(CaoZuoYuanDm);
        }

        /// <summary>
        /// 校验入参的必须值
        /// </summary>
        /// <returns></returns>
        public virtual bool CheckData()
        {
            if (YiYuanDm.Length > 20 || YiYuanDm.Trim() == "")
            {
                _ErrText = "医院编号(" + YiYuanDm + ")不能大于20位或空";
                return false;
            }

            if (CaoZuoYuanDm.Length > 8 || CaoZuoYuanDm.Trim() == "")
            {
                _ErrText = "操作员(" + CaoZuoYuanDm + ")不能大于8位或空";
                return false;
            }

            if (YeWuZqh.Length > 36)
            {
                _ErrText = "业务周期号(" + YeWuZqh + ")不能大于36位";
                return false;
            }

            if (YiYuanJylsh.Length > 40)
            {
                _ErrText = "医院交易流水号(" + YiYuanJylsh + ")不能大于40位";
                return false;
            }

            return true;
        }

        /// <summary>
        /// 组装成医保要求的入参格式
        /// </summary>
        /// <returns></returns>
        public virtual string GetInputStr()
        {
            //业务编号^医疗机构编号^操作员编号^业务周期号|参保地统筹区^医院交易流水号^持卡类型^入参^联机标志
            string inputStr = string.Format("{0}^{1}^{2}^{3}|{4}^{5}^{6}^{7}^{8}^",
                JiaoYiLx, YiYuanDm, CaoZuoYuanDm, YeWuZqh, CanBaoDtcq, YiYuanJylsh, KaLeiXing, RuCan, LianJiBz);
            return inputStr;
        }
    }
}